DEVICE DATASTORE

0.1 Introduction

The DATASTORE device, is used to manage the reads and writesof the removable memory MMC (Multi Media Card) and in the non-removable memory (NAND) of the Qmove family instruments.

0.2 Installation

0.2.1 DEVICE DECLARATION IN THE CONFIGURATION UNIT

In the configuration unit, the BUS section must be declared so that you have the hardware resources required for the implementation of the DATASTORE device.

;---------------------------------
; Internal device declaration
;---------------------------------
INTDEVICE
<device name>    DATASTORE          TCamp          <port_type>

where:

<device name>The name given to the device.
DATASTOREKeyword that identifies the device.
TcampTime sampling device (1÷10 ms).
<port type>Connected port type (MMC on port 0)

0.2.1.1 Example

;--------------------------------
; Internal device declaration
;--------------------------------
INTDEVICE
DEV        DATASTORE        0001        0

0.3 Operation

0.3.1 INTRODUCTION

The access to MMC storage device, it is implemented through a “file_system” and not with direct access. In this way the saved data can be shared with any PC and the device is seen by it as a simple floppy disk.

File system features The file system supports the following types of FAT:
FAT12 Used on floppy disks or storage devices with limited capacity.
FAT16 Used in most storage devices. It can get to store 2 GB of data.
FAT32 Used in high-capacity storage devices, over 2 GB.

The file-system implemented, allows access to the file for reading and writing. Does not allow you to create directories, and then those files must be present in the single “root directory” . The device is also able to open/create files whose names or ASCII conversion of a number and the extension is fixed.

Supports two types of files:

0.3.2 FILES AND DATAS FORMAT

Supported file formats are the BINART and the CSV. In our implementation are available the reading and appending functions (writing to END file), but not overwrite function on all types of files.

BINARY format The binary files have “hex” extension. In our implementation you can write and read a binary file where data values are stored in long (32bits) in hexadecimal base (HEX). To write or read such a file you must set the parameter filetype = 0.

0.3.2.1 Example:

If in the olongXX variables we have the following values:

olong01 = 0 => H'00000000
olong02 = -1 => H'FFFFFFFF
olong03 = 10000 => H'00002710
olong04 = -10000 => H'FFFFD8F0

We run the WRITE command by setting the parameter “field = 4”, we get to the end of the file:

00000000FFFFFFFF00002710FFFFD8F0''

CSV format The csv file will have “csv” extension. Data written in these files are organized in a table formed from a settable number of columns, each column is called a “field”. The rows of the table are called “record”. The DATASTORE device does not consider the presence of the record header. The maximum number of field is set to 32 (ilong / olong).

To write some long data type, “10000”, “-1”, “2147483647” and “-2147483648”, by setting the “filetype = 1” parameter, we will have:
The file system supports the following types of FAT:

Field1------------ +Field2--------- +Field3-------- +Field4-----+
10000              -1               2147483647      '2000000000

In this way the occupation of space in each record is fixed. If we set instead “filetype = 3”, we will have:

10000;-1;2147483647;'2000000000

The major evaluation software including Microsoft Excel, OpenOffice, Lotus 123, successfully read the fixed width file (filetype = 1) but when you save it into file with the field delimiters (filetype = 3).
The main difference between a format and the other is in the search of records.
Read a particular record using the format 1, It is not difficult as the start position within the file can be calculated easily given the record length is fixed.
Read instead a record with the format 2, implies a search within the file record start position. This operation may be long.

0.3.3 ACCESS TO FILES

To use the (MMC) storage device You must use the device command that allows to recognize it and activate it. The MOUNT command allow to execute this operationn. The device will be activated when the state st_mount take the value 1.
Please note that after each command, the device marks is handling that command with the st_busy state. When the st_busy state is to 1 the device cannot access other commands.
To open an existing file or open a new file, set the filetype parameter. It allows you to specify the format of the file you intend to treat.
Below we will divide the discussion on whether the filetype parameter takes the following values:
a) 0: binary files;
b) 1-2: CSV file with fixed space for data;
c) 3-4: CSV file with data separated by “;”.
Before sending the command of opening the file you have to specify which file is open with the filenuum parameter.
If the file is present in the storage device it is open otherwise it creates a new file with the name specified in filenum file.
When the st_openfile state is to 1 the file is opened.

a) In the binary files data is present one after the other. It's possible:

To read one or more data to a binary file, you must set the record parameter what data you begin reading and in the filed parameter how much data to read up to 32 data with one reading. At this point you have to use the READ command.
Data read are shown in the ilong01÷ ilong32 parameters.

0.3.3.1 Example:

Reading of 3 data in the position 11, 12, 13 in the binary file.

DEV:record=11
DEV:field=3
READ DEV
WAIT NOT DEV: st_busy
glVar1=DEV: ilong01
glVar2=DEV: ilong02
glVar3=DEV: ilong03

To write one or more data to a binary file you must set therecord parameter what data start overwrite and in the field parameter how much data will overwrite.
Data values by overwriting the data in the file should be inserted into olong01÷ olong32 parameters.

0.3.3.2 Example:

Writing of 3 datas int the position 11, 12, 13 in the binary file.

DEV:record=11
DEV:field=3
DEV:olong01=123        ;first data
DEV:olong02=456        ;second data
DEV:olong03=789        ;third data
WRITE DEV
WAIT NOT DEV: st_busy

To append new data to a binary file, you must use the method described above remembering to set the record parameter to -1.

B) In the CSV files with fixed datas space, is creates a table with columns, called field, and rows, called record. The field numbers with which to create the table you must specify before you open the new file in the field parameter.
For each entry in this table is reserved a fixed space. In this way each record, composed of a number field of data, fixed space in file.
To read a record of such a file, you must set in the record parameter, the number of records to read and send the READ command. In the ilong01-ilong32 parameters, are shows the read values from the record.

To overwrite a record of such a file, set the parameter records the number of records to write, set in the olong01-olong32 paramenters a number of values equal to the number of field in the record and then send the WRITE command.
To append a new record to the file you must set the value -1 in record.

0.3.3.3 Esempio:

Lettura del record 3 (Composto di tre field):

DEV:record = 3
READ DEV
glVar1 = DEV:ilong01
glVar2 = DEV:ilong02
glVar3 = DEV:ilong03

C) Come nel caso B, ma in questo caso non è possibile leggere o sovrascrivere un particolare record. E' possibile solo leggere in modo sequenziale tutto il file e scrivere solo aggiungendo un nuovo record.

Tabella riassuntiva:

Operazioni filetype
01-23-4
OPEN/CLOSE
DELETE
READ record sequenziali*
READ record indicizzati* *no
WRITE aggiunge un record
WRITE sovrascrive recordno

* = READ record sequenziali: lettura dei record presenti nel file partendo dal primo record fino all'ultimo. Questo tipo di lettura non prevede la possibilità di leggere record in ordine casuale all'interno del file. Questo tipo di lettura prevede solo di leggere i record partendo dal primo e leggendo sempre il successivo all'ultimo letto
* * = READ record indicizzati: questo tipo di lettura permette di leggere qualsiasi record presente nel file anche in ordine casuale.

0.4 Tabella comandi e parametri

0.4.1 SIMBOLOGIA ADOTTATA

Il nome del parametro, stato o comando è riportato alla sinistra della tabella.

R
Indica se il relativo parametro o stato è ritentivo (al momento dell’inizializzazione del device mantiene lo stato precedentemente definito), oppure lo stato che assume al momento dell’inizializzazione del device.
Se il device non necessita d'inizializzazione il campo “R” indica il valore che il parametro o stato assume all’accensione della scheda.
R = Ritentivo
0 = Al momento dell’inizializzazione del device il valore è forzato a zero.
1 = Al momento dell’inizializzazione del device il valore è forzato a uno.
- = Al momento dell’inizializzazione del device è presentato il valore significativo.

D
Indica la dimensione del parametro.
F = Flag
B = Byte
W = Word
L = Long
S = Single Float

0.4.1.1 Condizioni

Sono descritte tutte le condizioni necessarie affinché il parametro sia considerato corretto o perché il comando sia accettato.
In alcuni casi sono specificati dei valori limite per l’accettazione del parametro: se sono introdotti dei valori esterni ai limiti impostati, il dato è in ogni caso accettato; pertanto devono essere previsti opportuni controlli dell’applicativo tali da garantire il corretto funzionamento.
Per l’esecuzione di un comando, tutte le relative condizioni devono necessariamente essere soddisfatte; in caso contrario il comando non è inviato.

A
Indica il modo d'accesso.
R = Read (lettura).
W = Write (scrittura).
RW,= Read / Write.

0.4.2 Parametri

Di seguito sono presentati i parametri, variabili, stati e comandi necessari all’esecuzione del device.

NomeDRACondizioniDescrizione
priorityB5R-W-Priority
Nei prodotti della serie Qmove indica la priorità di esecuzione del device rispetto all'esecuzione dei tasks QCL e del display (Range 0÷10).
Nei prodotti della serie Qmove+ indica il media a cui il device fa riferimento (0 = SD/MMC, 1=NAND interna, 2= USB).
filetypeB0R-W-File Format
Definisce le caratteristiche del file (Range 0÷4):

Tipo 0
type = BINARY
record non separati
field non separati da“,”
non sono usati gli apici
intestazione non presente

Tipo 1
type = CSV
record separati da = carrige return and line feed (Windows)
field separati da spazi
non sono usati gli apici
intestazione non presente

Tipo 2
type = CSV
record separati da = line feed (Unix)
field separati da spazi
non sono usati gli apici
intestazione non presente

Tipo 3
type = CSV
record separati da = carrige return and line feed (Windows)
field separati da = “;” (hex 3b)
non sono usati gli apici
intestazione non presente

Tipo 4
type = CSV
record separati da = line feed (Unix)
field separati da = “;” (hex 3b)
non sono usati gli apici
intestazione non presente
fieldW0R-Wfiletype=0÷4Field
Nel caso in cui filetype=0, indica il numero di record da sovrascrivere a partire dal record indicato dal parametro record.
Nel caso in cui filetype=1÷4 indica il numero di campi che saranno scritti per ogni record.
Il valore è utilizzato esclusivamente con la creazione di un nuovo file.
(Range 0÷32)
filenumL0R-W-File Number
Definisce il “filename” del file da aprire considerando la conversione del numero in caratteri ASCII. (Range 0÷99999999)

0.4.3 Variabili

NomeDRACondizioniDescrizione
disksizeL0R-Disk Size
Indica la dimensione del dispositivo di memorizzazione in bytes.
Il valore è aggiornato al momento dell’esecuzione del comando MOUNT.
diskfreeL0R-Disk Free
Indica lo spazio libero sul dispositivo di memorizzazione in bytes.
Il valore è aggiornato al momento dell’esecuzione del comando MOUNT ed alla chiusura e scrittura di un file.
filesizeL0R-File Size
Indica la dimensione del file in bytes.
Il valore è aggiornato al momento dell’apertura e ad ogni successiva operazione di scrittura.
numrecordL0Rst_openfileFile Record Number
Indica il numero di record presenti nel file.
Il valore è aggiornato al momento dell’apertura e ad ogni successiva operazione di scrittura.
Se 0 significa che il file non contiene record formattati correttamente (viene settata anche la variabile error), oppure che si tratta di un nuovo file.
numfieldW0R-Field Number
Indica il numero di campi presenti nel primo record letto.
Il valore è aggiornato al momento della prima apertura o al momento della prima scrittura.
recordL0R-W-Record Number
Indica il numero di record (row) che è processato dai comandi WRITE e READ.
Se –1, con il comando WRITE sarà eseguito un accodamento.
ilong01÷32L0R-Input Long nr. 1 – 32
ibyte0B0R-Input Byte 0 (LSB) ilong01
Indica il byte nr. 0 (LSB) della long ilong01
ibyte1B0R-Input Byte 1 ilong01
Indica il byte nr. 1 della long ilong01
ibyte2B0R-Input Byte 2 ilong01
Indica il byte nr. 2 della long ilong01
ibyte3B0R-Input Byte 3 (MSB) ilong01
Indica il byte nr. 3 (MSB) della long ilong01.
olong01  xxxxxxxx
obyte3  xx------ (MSB)
obyte2  --xx---- +
obyte1  ----xx-- +
obyte0  ------xx (LSB) 
olong01-32L0R-W-Output Long nr. 1 – 32
obyte0B0R-W-Output Byte 0 (LSB) olong01
Indica il byte nr. 0 (LSB) della long olong01
obyte1B0R-W-Output Byte 1 olong01
Indica il byte nr. 1 della long olong01
obyte2B0R-W-Input Byte 2 olong01
Indica il byte nr. 2 della long olong01
obyte3B0R-W-Input Byte 3 (MSB) olong01
Indica il byte nr. 3 (MSB) della long olong01.
ilong01 xxxxxxxx
ibyte3 xx------ (MSB)
ibyte2 --xx---- +
ibyte1 ----xx-- +
ibyte0 ------xx (LSB) 
errcodeB0R-Error Code
Indica l’ultimo errore occorso nell’esecuzione dei comandi di gestione del device.
0 = no error
1 = n.d. (reserved)
2 = open file error
3 = read data error
4 = write data error
5 = file system error (reserved)
6 = file system error (reserved)
7 = file system error (reserved)
8 = file system error (reserved)
9 = file system error (reserved)
10 = record format error
11 = unknow error
errvalueB0R-Error Value
Sempre 0.
wrncodeB0R-Warning Code
Indica l’ultimo warning occorso nell’esecuzione dei comandi di gestione del device.
0 = no warning
1 = warning data
2 = warning command
3 = device not inserted
wrnvalueB0R-Warning Value
Sempre 0.

0.4.4 Stati

NomeDRACondizioniDescrizione
st_mountF0R-Device Mount
L’attivazione indica che è inserito un dispositivo di memorizzazione.
Il device verifica la presenza di un nuovo dispositivo a seguito del comando MOUNT.
st_openfileF0R-Open file
L’attivazione indica che il file è stato aperto/creato correttamente.
La mancata attivazione potrebbe indicare o un errore d'apertura del file: l’errore è segnalato dalla variabile “error”.
st_busyF0R-Busy
L’attivazione indica che il sistema è occupato in un’operazione d'accesso e che quindi non si deve togliere il supporto di memorizzazione.
st_errorF0R-Error
st_warningF0R-Warning

0.4.5 Comandi

NomeDRACondizioniDescrizione
MOUNT---st_openfile = 0Mount Device
Verifica la presenza di un nuovo dispositivo, quindi se rilevato.
Lo stato st_mount diventa 1.
UMOUNT---st_openfile = 0Unmount Device
Questo comando serve a “chiudere” il dispositivo in modo che possa essere rimosso.
Lo stato st_mount diventa 0.
OPENFILE---st_mount = 1
st_openfile = 0
Open File
Esegue l’apertura del file “filenum”. Se il file non esiste, è creato.
Lo stato st_openfile diventa 1.
CLOSEFILE---st_openfile = 1Close File
Chiude il file “filenum”.
Lo stato st_openfile diventa 0.
DELFILE---st_mount = 1
st_openfile = 0
Delete File
Elimina il file “filenum”. Per essere cancellato, il file deve essere chiuso.
READ---st_openfile = 1Read Record
Esegue la lettura del record indicato dalla variabile “record”.
Tutti i field letti sono posti nelle variabili ilongXX da ilong01.
WRITE---st_openfile = 1Append Record
Esegue l’accodamento di un nuovo record, prelevando i valori dalle variabili olongXX a partire da olong01.
RSERR----Clear Error
Azzera la segnalazione del parametro st_error e le variabili errcode ed errvalue.
RSWRN----Clear Warning
Azzera la segnalazione del parametro st_warning e le variabili wrncode ed wrnvalue.

0.5 Limitazioni

I dati tipo SINGLE non sono trattati. È necessario convertire questi dati di tipo interno prima di trasferirli nella MMC.

0.6 Esempio applicativo

0.6.1 VERIFICA DI UN DISPOSITIVO:

WAIT NOT DEV:st_busy               ; necessaria perché il device alla momento del RUN
                                   ; è in uno stato di busy finchè non termina
                                   ; le operazioni di inizializzazione.
MOUNT DEV                          ; esegue il MOUNT del dispositivo
WAIT NOT DEV:st_busy               ; attende il termine dell’operazione
IF DEV:st_mount                    ; se il dispositivo è presente,
  <operazioni>                     ;lo stato st_mount è 1
ENDIF

0.6.2 APERTURA DI UN FILE

DEV:filetype = 0                   ; imposta il tipo di file BINARY
DEV:filenum = 123                  ; imposta il nome del file come “123.hex”
WAIT NOT DEV:st_busy
OPENFILE DEV                       ; esegui il comando di apertura
WAIT NOT DEV:st_busy               ; attende il termine dell’operazione
IF DEV:st_openfile                 ; se il file viene aperto correttamente,
  <operazioni>                     ;lo stato st_openfile è 1
ENDIF

0.6.3 SCRITTURA DI ALCUNI RECORD, A PARTIRE DAL FILE APERTO IN PRECEDENZA:

DEV:field = 2                      ; imposta il numero di campi di cui
                                   ; è composto il record
                                   ; Nota: se il tipo di file è BINARY,
                                   ; questo parametro indica il numero di long
                                   ; che verranno scritte/lette.
DEV:record = -1                    ; indica al device di eseguire l’operazione a
                                   ; partire dalla fine del file (accodamento).
DEV:olong01 = 123456               ; imposta il dato da scrivere
DEV:olong02 = 654321
WAIT NOT DEV:st_busy
WRITE DEV                          ; esegui il comando di scrittura
WAIT NOT DEV:st_busy               ; attende il termine dell’operazione
IF DEV:st_error                    ; verifica se ci sono stati errori in scrittura
  <errore>
ENDIF